package com.fight.strive.sys.modules.redis;

import com.fight.strive.sys.modules.web.SpringContextHolder;

import java.util.List;
import java.util.concurrent.TimeUnit;

public class RedisUtils {

    /**
     * 向 Redis 中设值
     *
     * @param key   key
     * @param value value
     */
    static public void valueSet(String key, Object value) {
        RedisService redisService = SpringContextHolder.getBean(RedisService.class);
        redisService.valueSet(key, value);
    }

    /**
     * 向 Redis 中设值
     *
     * @param key      key
     * @param value    value
     * @param timeout  时间
     * @param timeUnit 时间单位
     */
    static public void valueSet(String key, Object value, long timeout, TimeUnit timeUnit) {
        RedisService redisService = SpringContextHolder.getBean(RedisService.class);
        redisService.valueSet(key, value, timeout, timeUnit);
    }

    /**
     * 获取 redis 值
     *
     * @param key key
     * @param clz 类型
     * @param <T> T
     * @return 返回值
     */
    static public <T> T valueGet(String key, Class<T> clz) {
        RedisService redisService = SpringContextHolder.getBean(RedisService.class);
        return redisService.valueGet(key, clz);
    }

    /**
     * 删除 Redis 中的值
     *
     * @param key 键
     */
    static public void valueDelete(String key) {
        RedisService redisService = SpringContextHolder.getBean(RedisService.class);
        redisService.valueDelete(key);
    }

    /**
     * 设置 redis 值
     *
     * @param key      key
     * @param objKey   objKey
     * @param objValue objValue
     */
    static public void hashPut(String key, Object objKey, Object objValue) {
        RedisService redisService = SpringContextHolder.getBean(RedisService.class);
        redisService.hashPut(key, objKey, objValue);
    }

    /**
     * 获取 redis 值
     *
     * @param key    key
     * @param objKey objKey
     * @param clz    clz
     * @param <T>    泛型
     * @return T
     */
    static public <T> T hashGet(String key, Object objKey, Class<T> clz) {
        RedisService redisService = SpringContextHolder.getBean(RedisService.class);
        return redisService.hashGet(key, objKey, clz);
    }

    /**
     * 获取 redis 列表值
     *
     * @param key    key
     * @param objKey objKey
     * @param clz    clz
     * @param <T>    泛型
     * @return List<T> list
     */
    static public <T> List<T> hashGetList(String key, Object objKey, Class<T> clz) {
        RedisService redisService = SpringContextHolder.getBean(RedisService.class);
        return redisService.hashGetList(key, objKey, clz);
    }

    /**
     * 删除 hash key
     *
     * @param key    key
     * @param objKey objKey
     */
    static public void hashDelete(String key, Object objKey) {
        RedisService redisService = SpringContextHolder.getBean(RedisService.class);
        redisService.hashDelete(key, objKey);
    }
}
